#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
//选用单链表的数据结构
struct student 
{ 
	char name[20];
	char gender[10];
	char num[20];
	float math;
	float english;
	float py;
	float sum;			//总分
	float average;		//平均分
	float weight ;		//权重
};
//所有关于数据的地方都要修改
struct Node
{
	struct student  data;
	struct Node* next;
};
struct Node* list;
//创建表头-->创建结构体变量
struct Node* createHead()
{
	struct Node* headNode = (struct Node*)malloc(sizeof(struct Node));
//	assert(headNode);			//断言
	headNode->next = NULL;
	return headNode;
}
struct Node* createNode(struct student data)
{
	struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
//	assert(newNode);
	//->
	newNode->data = data;
	(*newNode).next = NULL;
	return newNode;
}
void insertData(struct Node* headNode, struct student data)
{
	struct Node* newNode = createNode(data);
	newNode->next = headNode->next;
	headNode->next = newNode;
}
void insertDataBy_R(struct Node* headNode, struct student data)//尾插
{
	struct Node* r;
	r=headNode;    //找尾巴
	while(r->next!=NULL){
		r=r->next;
	}
	struct Node* newNode = createNode(data);
	r->next=newNode;
}
//从任意位置插入
void insertDataBy_any(struct Node* headNode, struct student data, int position) {
    // 创建新节点
    	struct Node* newNode = createNode(data);

    // 如果插入位置为 0，将新节点作为头节点
    if (position == 1) {
        newNode->next = headNode->next;
	    headNode->next = newNode; 
        return;
    }

    // 找到插入位置的前一个节点
    struct Node* current = headNode;
    int i;
    for (i = 0; i < position-1  && current != NULL; i++) {
        current = current->next;
    }

    // 如果插入位置无效，则不进行插入
    if (current == NULL)
        return;

    // 插入新节点
    newNode->next = current->next;
    current->next = newNode;
}
//写入文件
void WriteWight(struct Node* headNode, const char* fileName) //const char*是指向可更改char的常量指针 
{
	struct Node* pmove = headNode->next;
		FILE* fp = fopen(fileName, "w");
		while (pmove != NULL) 
		{
			fprintf(fp, "%s\t%s\t%s\t%5.2f\t%5.2f\t%5.2f\t%5.2f\t%5.2f\n", pmove->data.name,
				pmove->data.gender,pmove->data.num, pmove->data.math, pmove->data.english, pmove->data.py,
				pmove->data.sum, pmove->data.average);
			pmove = pmove->next;
		}
		fclose(fp);
}
void swapData(struct Node* a, struct Node* b) {
    student temp = a->data;
    a->data = b->data;
    b->data = temp;
}
void sortList_weight_big(struct Node* headNode) { 
    if (headNode->next == NULL)
        return;

    int swapped;
    struct Node* current;
    struct Node* last = NULL;
    do {
        swapped = 0;
        current = headNode->next;
        while (current->next != last) {
            if (current->data.weight < current->next->data.weight) {
                swapData(current, current->next);
                swapped = 1;
            }
            current = current->next;
        }
        last = current;
    } while (swapped);
}
void CalculatedWeight(struct Node* headNode)
{	
if(headNode->next==NULL)
	{
		printf("链表为空！\n");
		system("pause");		//按任意键继续
		return;
	}
	float a,b,c;
		float WG;
		printf("请输入数学 英语 物理的权重：\n");
		scanf("%f%f%f",&a,&b,&c);
	struct Node* p=headNode->next;		//接受用户的输入
	while(p!=NULL){
		WG=a*p->data.math+b*p->data.english+c*p->data.py;
			p->data.weight=WG;
			p=p->next;
	}
	sortList_weight_big(list);
	WriteWight(list,"student.txt");
}
void printList(struct Node* headNode) 
{
	if(headNode->next==NULL)
	{
		printf("链表为空！\n");
		return;
	}
	struct Node* pmove = headNode->next;
	printf("姓名\t性别\t学号\t数学\t英语\t物理\t总分\t平均分\n");
	while (pmove != NULL) 
	{
		printf("%s\t%s\t%s\t%5.2f\t%5.2f\t%5.2f\t%5.2f\t%5.2f\n", pmove->data.name,
			pmove->data.gender,pmove->data.num, pmove->data.math, pmove->data.english, pmove->data.py, 
			pmove->data.sum, pmove->data.average);
		pmove = pmove->next;
	}
}
void printListA(struct Node* headNode) 
{
	int headcount=0;
	int ManNum=0;
	int WomanNum=0;
	
	if(headNode->next==NULL)
	{
		printf("链表为空！\n");
		return;
	}
	struct Node* pmove = headNode->next;
	printf("姓名\t性别\t学号\t数学\t英语\t物理\t总分\t平均分\n");
	while (pmove != NULL) 
	{
		headcount++;
		printf("%s\t%s\t%s\t%5.2f\t%5.2f\t%5.2f\t%5.2f\t%5.2f\n", pmove->data.name,
			pmove->data.gender,pmove->data.num, pmove->data.math, pmove->data.english, pmove->data.py, 
			pmove->data.sum, pmove->data.average);
		if(!strcmp(pmove->data.gender,"男")){
			ManNum++;
		}	
		else{
			WomanNum++;
		}	
		pmove = pmove->next;	
	}
		printf("班级人数：%d\n",headcount);
		printf("男生人数：%d\n",ManNum);
		printf("女生人数：%d\n",WomanNum);
}
void printAll(struct Node* headNode) 
{
	if(headNode->next==NULL)
	{
		printf("链表为空！\n");
		system("pause");		//按任意键继续
		return;
	}
	struct Node* pmove = headNode->next;
	printf("姓名\t性别\t学号\t数学\t英语\t物理\t总分\t平均分\t加权成绩\t\n");
	while (pmove != NULL) 
	{
		printf("%s\t%s\t%s\t%5.2f\t%5.2f\t%5.2f\t%5.2f\t%5.2f\t%5.2f\n", pmove->data.name,
			pmove->data.gender,pmove->data.num, pmove->data.math, pmove->data.english, pmove->data.py, 
			pmove->data.sum, pmove->data.average,pmove->data.weight);
		pmove = pmove->next;
	}
}
//清空表格
bool ClearList(struct Node* headNode)
{
struct Node *p,*q;	
	p=headNode->next;
	while(p!=NULL){
		q=p->next;
		free(p) ;
		p=q;
	}
	headNode->next=NULL;	
}
//通过名字删除
void deleteDataByName(struct Node* headNode, const char* name)
{
	struct Node* preNode = headNode;
	struct Node* curNode = headNode->next;
	while (curNode != NULL && strcmp(curNode->data.name,name)) 
	{
		preNode = curNode;
		curNode = preNode->next;
	}
	if (curNode==NULL) 
	{
		printf("删除失败!,没有找到指定数据！\n");
	}
	else 
	{
		preNode->next = curNode->next;
		free(curNode);
	}
}
void deleteDataByNum(struct Node* headNode, const char* num)
{
	struct Node* preNode = headNode;
	struct Node* curNode = headNode->next;
	while (curNode != NULL && strcmp(curNode->data.num,num)) 
	{
		preNode = curNode;
		curNode = preNode->next;
	}
	if (curNode==NULL) 
	{
		printf("删除失败!,没有找到指定数据！\n");
	}
	else 
	{
		preNode->next = curNode->next;
		free(curNode);
	}	
}
struct Node* searchDataByName(struct Node* headNode, const char* name) 
{
	struct Node* pmove = headNode->next;
	while (pmove != NULL && strcmp(pmove->data.name,name)) 
	{
		pmove = pmove->next;
	}
	return pmove;
}
//通过学号找学生
struct Node* searchDataByNum(struct Node* headNode, const char* num){
	struct Node* pmove = headNode->next;
		while (pmove != NULL && strcmp(pmove->data.num,num)) 
		{
			pmove = pmove->next;
		}
		return pmove;
};

//管理系统文件操作
//写文件
void saveToFile(struct Node* headNode, const char* fileName) //const char*是指向可更改char的常量指针 
{
	struct Node* pmove = headNode->next;
	FILE* fp = fopen(fileName, "w");
	while (pmove != NULL) 
	{
		fprintf(fp, "%s\t%s\t%s\t%5.2f\t%5.2f\t%5.2f\t%5.2f\t%5.2f\n", pmove->data.name,
			pmove->data.gender,pmove->data.num, pmove->data.math, pmove->data.english, pmove->data.py,
			pmove->data.sum, pmove->data.average);
		pmove = pmove->next;
	}
	fclose(fp);
}

//读文件
void readFromFile(struct Node* headNode, const char* fileName) 
{
	FILE* fp = fopen(fileName, "r");
	if (fp == NULL) 
	{
		fp = fopen(fileName, "w+");
		fclose(fp);
	}
	struct student temp;
	while (fscanf(fp, "%s\t%s\t%s\t%f\t%f\t%f\t%f\t%f\n",
		temp.name,
		temp.gender,
		temp.num,
		&temp.math,
		&temp.english,
		&temp.py,
		&temp.sum,
		&temp.average) != EOF) 
	{
		insertData(list, temp);
	}
	fclose(fp);
}
void DeleteMenu()
{
	printf("---------【学生删除功能】------------\n");
		printf("\t\t0.退出功能\n");
		printf("\t\t1.按学生名字查找并删除\n");
		printf("\t\t2.按学生学号查找并删除\n");
		printf("-------------------------------------\n");
		printf("请输入(0~2):");
}
void ChangeMenu()
{
	printf("---------【学生修改功能】------------\n");
		printf("\t\t0.退出功能\n");
		printf("\t\t1.按学生名字查找并修改\n");
		printf("\t\t2.按学生学号查找并修改\n");
		printf("-------------------------------------\n");
		printf("请输入(0~2):");
}
void SearchMenu()
{
	printf("---------【学生查询功能】------------\n");
	printf("\t\t0.退出功能\n");
	printf("\t\t1.按学生名字查找\n");
	printf("\t\t2.按学生学号查找\n");
	printf("-------------------------------------\n");
	printf("请输入(0~2):");		
}
void insertMenu()//让用户选择头插还是尾插
{
	printf("---------【学生录入系统】------------\n");
	printf("\t\t0.退出功能\n");
	printf("\t\t1.从表格头部开始插入\n");
	printf("\t\t2.从表格尾部开始插入\n");
	printf("\t\t3.从任意位置开始插入\n");
	printf("-------------------------------------\n");
	printf("请输入(0~3):");		
}
void sortMenu()
{
	printf("---------【学生排序系统】---------\n");
	printf("\t\t0.退出功能\n");
	printf("\t\t1.按英语成绩排序\n");
	printf("\t\t2.按数学成绩排序\n");
	printf("\t\t3.按物理成绩排序\n");
	printf("\t\t4.按加权成绩排序\n");
	printf("-------------------------------------\n");
	printf("请输入(0~4):");
}
void makeMenu()		  //制作菜单
{
	//排序+文件
	printf("---------【链式学生管理系统】---------\n");
	printf("*\t\t0.退出功能           *\n");
	printf("*\t\t1.录入功能           *\n");
	printf("*\t\t2.浏览功能           *\n");
	printf("*\t\t3.查找功能           *\n");
	printf("*\t\t4.修改功能           *\n");
	printf("*\t\t5.删除功能           *\n");
	printf("*\t\t6.排序功能           *\n");
	printf("*\t\t7.清空功能           *\n");
	printf("--------------------------------------\n");
	printf("请输入(0~7):");
}

void sortList_english_small(struct Node* headNode) {//a为想要排序的科目 
    if (headNode == NULL)
        return;

    int swapped;
    struct Node* current;
    struct Node* last = NULL;
    do {
        swapped = 0;
        current = headNode->next;
        while (current->next != last) {
            if (current->data.english > current->next->data.english) {
                swapData(current, current->next);
                swapped = 1;
            }
            current = current->next;
        }
        last = current;
    } while (swapped);
}
void swapData1( Node* a, Node* b) {
    char temp[100];
    strcpy(temp, a->data.num);
    strcpy(a->data.num, b->data.num);
    strcpy(b->data.num, temp);
}

// 对单链表中的字符串进行排序
void sortStrings(Node** head) {
    if (*head == NULL || (*head)->next == NULL) {
        return;  // 链表为空或只有一个节点，无需排序
    }

    Node* curr;
    Node* ptr;
    for (curr =  (*head)->next; curr->next != NULL; curr = curr->next) {
        for (ptr = curr->next; ptr != NULL; ptr = ptr->next) {
            if (strcmp(curr->data.num, ptr->data.num) > 0) {
                swapData1(curr, ptr);
            }
        }
    }
}

void sortList_english_big(struct Node* headNode) {//a为想要排序的科目 
    if (headNode == NULL)
        return;

    int swapped;
    struct Node* current;
    struct Node* last = NULL;
    do {
        swapped = 0;
        current = headNode->next;
        while (current->next != last) {
            if (current->data.english < current->next->data.english) {
                swapData(current, current->next);
                swapped = 1;
            }
            current = current->next;
        }
        last = current;
    } while (swapped);
}
void sortList_math_small(struct Node* headNode) {//a为想要排序的科目 
    if (headNode == NULL)
        return;

    int swapped;
    struct Node* current;
    struct Node* last = NULL;
    do {
        swapped = 0;
        current = headNode->next;
        while (current->next != last) {
            if (current->data.math > current->next->data.math) {
                swapData(current, current->next);
                swapped = 1;
            }
            current = current->next;
        }
        last = current;
    } while (swapped);
}
void sortList_math_big(struct Node* headNode) {//a为想要排序的科目 
    if (headNode == NULL)
        return;

    int swapped;
    struct Node* current;
    struct Node* last = NULL;
    do {
        swapped = 0;
        current = headNode->next;
        while (current->next != last) {
            if (current->data.math < current->next->data.math) {
                swapData(current, current->next);
                swapped = 1;
            }
            current = current->next;
        }
        last = current;
    } while (swapped);
}
void sortList_py_small(struct Node* headNode) { 
    if (headNode == NULL)
        return;

    int swapped;
    struct Node* current;
    struct Node* last = NULL;
    do {
        swapped = 0;
        current = headNode->next;
        while (current->next != last) {
            if (current->data.py > current->next->data.py) {
                swapData(current, current->next);
                swapped = 1;
            }
            current = current->next;
        }
        last = current;
    } while (swapped);
}
void sortList_py_big(struct Node* headNode) { 
    if (headNode == NULL)
        return;

    int swapped;
    struct Node* current;
    struct Node* last = NULL;
    do {
        swapped = 0;
        current = headNode->next;
        while (current->next != last) {
            if (current->data.py < current->next->data.py) {
                swapData(current, current->next);
                swapped = 1;
            }
            current = current->next;
        }
        last = current;
    } while (swapped);
}

//删除
void keyDownD()
{
	int userkey=0;
	struct student temp;			//接受用户的输入
	struct Node* result;
	scanf("%d", &userkey);		
	switch (userkey) {
		case 0:
					printf("----【退出模块】----\n");
					break;
		case 1:
			system("cls");			//清屏
			printf("----【删除功能】----\n");
					printf("请输入要删除学生姓名:");
					scanf("%s", temp.name);  //vs 增强版的函数，20 代表长度
					deleteDataByName(list, temp.name);
					saveToFile(list, "student.txt");
					printf("删除成功");
					system("pause");
			break;
		case 2:
			system("cls");			//清屏
			printf("----【删除功能】----\n");
					printf("请输入要删除学生学号:");
					scanf("%s", temp.num);  //vs 增强版的函数，20 代表长度
					deleteDataByNum(list, temp.num);
					saveToFile(list, "student.txt");
					printf("删除成功");
					system("pause");
			break;
		default:
			printf("输入错误!,请重新输入...!\n");
			break;
	}
}
//修改
void keyDowmC()
{
	int userkey=0;
	struct student temp;			//接受用户的输入
	struct Node* result;
	scanf("%d", &userkey);	
	switch (userkey) {
			case 0:
			printf("----【退出模块】----\n");
			break;
		case 1:
			system("cls");			//清屏
			printf("----【按学生名字修改】----\n");
			printf("请输入要修改学生姓名:");
					scanf("%s", temp.name);  //vs 增强版的函数，20 代表长度
					result = searchDataByName(list, temp.name);
					if (result == NULL)
					{
						printf("未找到结果！\n");
					}
					else
					{
						printf("请输入学生新的信息(姓名,性别,学号，数学,英语,物理):");
						scanf("%s%s%s%f%f%f", result->data.name,  result->data.gender,result->data.num,  &result->data.math, &result->data.english, &result->data.py);
						//手动处理:
						result->data.sum = result->data.math + result->data.english + result->data.py;
						result->data.average = result->data.sum / 3;
						saveToFile(list, "student.txt");
					}
			break;
		case 2:
			system("cls");			//清屏
			printf("----【按学生学号修改】----\n");
						printf("请输入要修改学生学号:");
								scanf("%s", temp.num);  //vs 增强版的函数，20 代表长度
								result = searchDataByNum(list, temp.num);
								if (result == NULL)
								{
									printf("未找到结果！\n");
								}
								else
								{
								printf("请输入学生新的信息(姓名,性别,学号，数学,英语,物理):");
								scanf("%s%s%s%f%f%f", result->data.name,  result->data.gender,result->data.num,  &result->data.math, &result->data.english, &result->data.py);
									//手动处理:
								result->data.sum = result->data.math + result->data.english + result->data.py;
								result->data.average = result->data.sum / 3;
								saveToFile(list, "student.txt");
								}
			break;
		default:
			printf("输入错误!,请重新输入...!\n");
			break;
	}
	
	
}
//查找
void keyDownB()
{
	int userkey=0;
	struct student temp;			//接受用户的输入
	struct Node* result;
	scanf("%d", &userkey);
	switch (userkey) {
		case 0:
			printf("----【退出模块】----\n");
			break;
		case 1:
			printf("----【按学生名字查找】----\n");
			printf("请输入要查找学生姓名:");
					scanf("%s", temp.name);  //vs 增强版的函数，20 代表长度
					result = searchDataByName(list, temp.name);
					if (result == NULL) 
					{
						printf("未找到结果！\n");
					}
					else 
					{
						printf("姓名\t性别\t学号\t数学\t英语\t物理\t总分\t平均分\n");
						printf("%s\t%s\t%s\t%5.2f\t%5.2f\t%5.2f\t%5.2f\t%5.2f\n",
							result->data.name,
							result->data.gender,
							result->data.num, 
							result->data.math, 
							result->data.english, 
							result->data.py,
							result->data.sum, 
							result->data.average);
					}
			break;
		case 2:
			printf("----【按学生学号查找】----\n");
						printf("请输入要查找学生学号:");
						scanf("%s", temp.num);  //vs 增强版的函数，20 代表长度
						result = searchDataByNum(list, temp.num);
						if (result == NULL) 
						{
							printf("未找到结果！\n");
						}
						else 
						{
						printf("姓名\t性别\t学号\t数学\t英语\t物理\t总分\t平均分\n");
						printf("%s\t%s\t%s\t%5.2f\t%5.2f\t%5.2f\t%5.2f\t%5.2f\n",
						result->data.name,
						result->data.gender,
						result->data.num, 
						result->data.math, 
						result->data.english, 
						result->data.py,
						result->data.sum, 
					 	result->data.average);
						}
			break;
		default:
			printf("输入错误!,请重新输入...!\n");
			break;
	}
	
}
//录入
void keyDownA() 
{
	while(1){
		int userkey = 0;
			struct student temp;			//接受用户的输入
			struct Node* result;
			scanf("%d", &userkey);
			switch (userkey) 
			{
			case 0:
				printf("----【退出模块】----\n");
				break;
			case 1:
				printf("----【从表格头部开始插入】----\n");
				printf("请输入学生信息(姓名 性别 学号 数学 英语 物理):\n");
				scanf("%s%s%s%f%f%f", temp.name,  temp.gender, temp.num,&temp.math, &temp.english, &temp.py);
				//手动处理:
				temp.sum = temp.math + temp.english + temp.py;
				temp.average = temp.sum / 3;
				insertData(list, temp);
				saveToFile(list, "student.txt");
				break;
			case 2:
				printf("请输入学生信息(姓名 性别 学号 数学 英语 物理):\n");
				scanf("%s%s%s%f%f%f", temp.name, temp.gender, temp.num,  &temp.math, &temp.english, &temp.py);
				//手动处理:
				temp.sum = temp.math + temp.english + temp.py;
				temp.average = temp.sum / 3;
				insertDataBy_R(list, temp);
				saveToFile(list, "student.txt");
				break;
						case 3:
				printf("----【从表格任意位置开始插入】----\n");
				printf("请输入学生信息(姓名 性别 学号 数学 英语 物理 位置):\n");
				int a;
				scanf("%s%s%s%f%f%f%d", temp.name,  temp.gender, temp.num ,&temp.math, &temp.english, &temp.py,&a);
				//手动处理:
				temp.sum = temp.math + temp.english + temp.py;
				temp.average = temp.sum / 3;
				insertDataBy_any(list, temp, a);//a为需要在表格中插入的位置 
				saveToFile(list, "student.txt");							
			default:
				printf("输入错误!,请重新输入...!\n");
				break;
			}
			if(userkey==0){
				break;
			}
			else {
				system("cls");			//清屏
				insertMenu();
			}
	}	
}
void keyDown5()
{
	CalculatedWeight(list);
	//sortList_weight_big(list);
	printAll(list);
}
void keyDown2()
{
	int userkey1 = 0;
	struct student temp;			//接受用户的输入
	struct Node* result;
	scanf("%d", &userkey1);
	switch (userkey1) 
	{
	case 0:
		printf("----【退出模块】----\n");
		system("pause");
		exit(0);
		break;

	case 1:
		system("cls");
	//	printf("----【按英语成绩排序】----\n");
		printf("----【按从小到大的顺序排序】----\n");
        sortList_english_small(list);
        printList(list);
		break;
	case 2:
		system("cls");
	//	printf("----【按英语成绩排序】----\n");
		printf("----【按从大到小的顺序排序】----\n");
        sortList_english_big(list);
        printList(list);
		break;
					
	default:
		printf("输入错误!,请重新输入...!\n");
		break;
	}
}
void keyDown3()
{
	int userkey1 = 0;
	struct student temp;			//接受用户的输入
	struct Node* result;
	scanf("%d", &userkey1);
	switch (userkey1) 
	{
	case 0:
		printf("----【退出模块】----\n");
		system("pause");
		exit(0);
		break;

	case 1:
		system("cls");
	//	printf("----【按英语成绩排序】----\n");
		printf("----【按从小到大的顺序排序】----\n");
        sortList_math_small(list);
        printList(list);
		break;
	case 2:
		system("cls");
	//	printf("----【按英语成绩排序】----\n");
		printf("----【按从大到小的顺序排序】----\n");
        sortList_math_big(list);
        printList(list);
		break;
					
	default:
		printf("输入错误!,请重新输入...!\n");
		break;
	}
}
void keyDown4()
{
	int userkey1 = 0;
	struct student temp;			//接受用户的输入
	struct Node* result;
	scanf("%d", &userkey1);
	switch (userkey1) 
	{
	case 0:
		printf("----【退出模块】----\n");
		system("pause");
		exit(0);
		break;

	case 1:
		system("cls");
	//	printf("----【按英语成绩排序】----\n");
		printf("----【按从小到大的顺序排序】----\n");
        sortList_py_small(list);
        printList(list);
		break;
	case 2:
		system("cls");
	//	printf("----【按英语成绩排序】----\n");
		printf("----【按从大到小的顺序排序】----\n");
        sortList_py_big(list);
        printList(list);
		break;
					
	default:
		printf("输入错误!,请重新输入...!\n");
		break;
	}
}
void keyDown1()
{
	int userkey1 = 0;
	struct student temp;			//接受用户的输入
	struct Node* result;
	scanf("%d", &userkey1);
	switch (userkey1) 
	{
	case 0:
		printf("----【退出模块】----\n");
		break;

	case 1:
		system("cls");
		printf("----【按英语成绩排序】----\n");
		printf("\t\t1.按从小到大顺序\n");
	    printf("\t\t2.按从大到小的顺序\n");
	    printf("-------------------------------------\n");
	    printf("请输入(1-2):");
	    keyDown2() ;
		//system("pause");
	//	system("cls");
              
		break;
	case 2:
		system("cls");
		printf("----【按数学成绩排序】----\n");
		printf("\t\t1.按从小到大的顺序\n");
	    printf("\t\t2.按从大到小的顺序\n");
	    printf("-------------------------------------\n");
	    printf("请输入(1-2):");
	    keyDown3() ;
		//system("pause");
	//	system("cls");
		break;
	case 3:
		system("cls");
		printf("----【按物理成绩排序】----\n");
		printf("\t\t1.按从小到大的顺序\n");
	    printf("\t\t2.按从大到小的顺序\n");
	    printf("-------------------------------------\n");
	    printf("请输入(1-2):");
	    keyDown4() ;
	//	system("pause");
	//	system("cls");
		break;
	case 4:
		system("cls");
		printf("----【按加权成绩排序】----\n");
	    keyDown5() ;
		//system("pause");
	//	system("cls");
		break;				
//	default:
//		printf("输入错误!,请重新输入...!\n");
//		break;
	}
}
//主控
void keyDown() 
{
	int userkey = 0;
	struct student temp;			//接受用户的输入
	struct Node* result;
	scanf("%d", &userkey);
	switch (userkey) 
	{
	case 0:
		printf("----【退出模块】----\n");
		system("pause");
		exit(0);
		break;
	case 1:
		system("cls");
		insertMenu();
		keyDownA();	
			break;
	case 2:
		system("cls");			//清屏
		printf("----【浏览功能】----\n");
	    sortStrings(&list);
		printListA(list);
		break;
	case 3:
		system("cls");
		SearchMenu();
		keyDownB();
		break;
	case 4:
		system("cls");			//清屏
		ChangeMenu();
		keyDowmC();
		break;
	case 5:
		system("cls");			//清屏
		DeleteMenu();
		keyDownD();
		break;
	case 6:
		system("cls");
		sortMenu();
		keyDown1();
		//system("pause");		//按任意键继续
	//	system("cls");
	    break;
	    	case 7:
		printf("------【清空列表】-----\n");
		ClearList(list);
		saveToFile(list, "student.txt");
		system("cls");			//清屏
		printf("列表已经清空！\n");
		break;
	default:
		printf("输入错误!,请重新输入...!\n");
		break;
	}
}
int main() 
{
	list = createHead();
	readFromFile(list, "student.txt");
	while (1) 
	{
		makeMenu();
		keyDown();
		system("pause");		//按任意键继续
		system("cls");			//清屏
	}
	return 0;
}